package com.eric.windows.event;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;


public class planeGrameActivity extends Activity {
    private int speed = 10;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去掉窗口标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
//        //全屏幕显示
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        final PlaneView planeView = new PlaneView(this);
        setContentView(planeView);
        planeView.setBackgroundColor(Color.WHITE);

        //获取屏幕宽度和高度
        Display display  = getWindowManager().getDefaultDisplay();
        DisplayMetrics metrics = new DisplayMetrics();
        display.getRealMetrics(metrics);
        planeView.currentX = metrics.widthPixels/2;
        planeView.currentY = metrics.heightPixels/2- 40;

        planeView.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                switch (event.getKeyCode()){
                    case KeyEvent.KEYCODE_S:
                        planeView.currentY  +=  speed;
                        break;
                    case KeyEvent.KEYCODE_W:
                        planeView.currentY  -=  speed;
                        break;
                    case KeyEvent.KEYCODE_A:
                        planeView.currentX  +=  speed;
                        break;
                    case KeyEvent.KEYCODE_D:
                        planeView.currentX  -=  speed;
                        break;
                }
                //通知重绘planeView
                planeView.invalidate();
                return true;
            }
        });

    }


}
